# model
from script.get_user_info.rating.codeforces import cf_rating
from model.update_rating_and_solve_number.config.config import update_rating_sleep_time
import pymongo
import time

def base_rating(dateset , uid_name , rating_name , get_rating):
    client = pymongo.MongoClient("mongodb://localhost:27017/")
    db = client["ACM_MEMBER"]
    collections = db[dateset]

    for collection in collections.find():
        uid = collection[uid_name]
        time.sleep(update_rating_sleep_time)
        try :
            rating_val = get_rating(uid)
        except :
            rating_val = 0
        collections.update_one({uid_name: uid}, {"$set": {rating_name: rating_val}})
    client.close()

if __name__ == '__main__':
    base_rating("CODEFORCES_INFORMATION", "codeforces_id" , "codeforces_rating" , cf_rating)